/*
 * Version 1.4
 */

$(document).ready(function(){

	var pages = [
		[ '#pHome', gPageHome ]
	];
	for (var i = 0; i < pages.length; i++){
		if ($(pages[i][0]).length === 1)
		pages[i][1]();
	}
	
	$('#nav li a').hover(function(){
		$(this).not('.active').find('span').stop().animate({'width':'100%'});
	},
	function(){
		$(this).not('.active').find('span').stop().animate({'width':0});	
	});
	
	$('.hassub').hover(function(){
		$('.ovl').show();
	},
	function(){
		$('.ovl').hide();	
	});
	
	$('#nav li').hover(function(){
		$(this).find('.subnav').stop().slideDown();
		$('.subnav li a').each(function(){
			var heightA = $(this).height();
			$(this).css({'margin-top': (57-heightA)/2});	
		});	
	},
	function(){
		$(this).find('.subnav').stop().slideUp();	
	});
	
	
	$('.ct_list .list:first').find('h4').addClass('active');
	$('.ct_list .list:first').find('.list_sh').addClass('active').show();
	
	$('.ct_list .list h4').click(function(){
		
		if($(this).next().hasClass('active')){
			$(this).removeClass('active');
			$(this).next().removeClass('active');
			$(this).next().stop().slideUp();		
		}else{
			$('.ct_list .list h4').removeClass('active');
			$('.ct_list .list .list_sh').removeClass('active');
			$('.ct_list .list .list_sh').slideUp();
			$(this).addClass('active');
			$(this).next().addClass('active');
			$(this).next().stop().slideDown();	
		}
		
	});
	

	$('.antiscroll-wrap').antiscroll();
	
	$('.ct_ip p').click(function(){
		$(this).hide();
		$(this).prev().focus();	
	});
	$('.ct_ip p').prev() .focusout(function() {
		var valIP = $(this).val();
		if(!valIP){
			$(this).next().show();	
		}
	});

});

var settings = {
};

var util = {
	object: {
		exists: function(obj) {
			return $(obj) != undefined && $(obj) != null;
		}
	},

	common:{
		commonInit: function(){
			// Fix placeholer HTML5
			$('input[placeholder], textarea[placeholder]').placeholder();
		},
		setupCurrentYear: function(objId){
			// Get current year
			if (util.object.exists(objId)) {
				now = new Date;
				theYear = now.getYear();
				if (theYear < 1900)	theYear = theYear+1900;
				$(objId).text(theYear);
			}
		},
		linkPageFadeout: function(objClass){
			$(objClass).click(function(){
				var href = $(this).attr('href');
				var target = $(this).attr('target');
				setTimeout('goToURL()', 1500);
				goToURL = function(){
					if (target == '_blank'){
						window.open(href, target);
						window.parent.location.reload();
					}
					else {
						window.location.reload();
						window.location = href;
					}
				}
				return false;
			});
		},
		measureText: function(pText, pFontSize, pStyle) {
			var lDiv = document.createElement('lDiv');

			document.body.appendChild(lDiv);

			if (pStyle != null) {
				lDiv.style = pStyle;
			}
			lDiv.style.fontSize = "" + pFontSize + "px";
			lDiv.style.position = "absolute";
			lDiv.style.left = -1000;
			lDiv.style.top = -1000;

			lDiv.innerHTML = pText;

			var lResult = {
				width: lDiv.clientWidth,
				height: lDiv.clientHeight
			};

			document.body.removeChild(lDiv);
			lDiv = null;

			return lResult;
		}
	},

	widget: {
		setupScroll: function(objClass) {
			// Init scrollbar
			if (util.object.exists(objClass)) {
				var ginScroll = $(objClass);
					ginScroll.tinyscrollbar();
					ginScroll.tinyscrollbar_update();
			}
		},
		initDot: function() {			
			[].slice.call( document.querySelectorAll( '.dotstyle > ul' ) ).forEach( function( nav ) {
				new DotNav( nav, {
					callback : function( idx ) {
						//console.log( idx )
					}
				} );
			} );		
		}
	}
};

var ui = {
	gPageHome:{
		init: function() {
			
		}
	}
}

$(function() {
	// util.common.commonInit();
	// util.common.setupCurrentYear("#currentYear");
});

function gPageHome() {
	ui.gPageHome.init();
}